package com.hdax.dm.rest.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hdax.dm.dao.user.DmLinkUserMapper;
import com.hdax.dm.entity.order.DmOrderLinkUser;
import com.hdax.dm.entity.user.DmLinkUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(path = "/linkUser")
@Api(value = "用户联系人测试接口",tags = "用户联系人测试接口")
public class DmLinkUserRestService {

    @Resource
    private DmLinkUserMapper linkUserMapper;

    //根据linkid返回联系人信息
    @PostMapping(path = "/findById")
    public DmLinkUser findById(@RequestParam("linkId")Long linkId){
        return linkUserMapper.selectById(linkId);
    }


    @ApiOperation(value = "根据用户id查询用户联系人信息")
    @PostMapping(path = "/findLinkUserByuserId")
    public List<DmLinkUser> findLinkUserByuserId(@RequestParam("userId")Long userId){
        QueryWrapper<DmLinkUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userId",userId);
        return linkUserMapper.selectList(queryWrapper);
    }

    //验证购票人是否已经存在
    @PostMapping(path = "/linkUserisExist")
    public DmLinkUser linkUserisExist(@RequestParam("idCard")String idCard){
        QueryWrapper<DmLinkUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("idCard",idCard);
        return linkUserMapper.selectOne(queryWrapper);
    }

    //添加常用购票人224365987536598
    @PostMapping(path = "/addLinkUser")
    public int addLinkUser(@RequestBody DmLinkUser dmLinkUser){
        return linkUserMapper.insert(dmLinkUser);
    }

    //删除购票人
    @PostMapping(path = "/deleteLinkUser")
    public int deleteLinkUser(@RequestParam("linkId")Long linkId){
        return linkUserMapper.deleteById(linkId);
    }
}
